﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DataRecv.models.device
{
    /// <summary>
    /// 设备实时状态
    /// </summary>
    public class DeviceState
    {
        
        /// <summary>
        /// 上传失败
        /// </summary>
        public bool UploadFail
        {
            get
            {
                return (fcount > 10);
            }
            set
            {
                if (value == true)
                {
                    fcount++;
                }
                else
                {
                    fcount = 0;
                }
            }
        }
        public DateTime UploadTime;
        private int fcount;
        
        /// <summary>
        /// 无数据
        /// </summary>
        public bool NoData;
        public DateTime NoDataTime;
        /// <summary>
        /// 超过十分钟就认为无数据
        /// </summary>
        private const int JUDGEMENT = 10;
        /// <summary>
        /// 最后一次经过时间
        /// </summary>
        public DateTime LastJGSJ;
        /// <summary>
        /// 端口
        /// </summary>
        public int Port;
        /// <summary>
        /// Ping状态
        /// </summary>
        public bool Ping;
        /// <summary>
        /// ping状态改变发生的时间
        /// </summary>
        public DateTime PingOccurTime;
        /// <summary>
        /// 注册ID
        /// </summary>
        public int LoginID;
        /// <summary>
        /// 通道号
        /// </summary>
        public int Channel;
        /// <summary>
        /// 是否开启
        /// </summary>
        public bool IsOpen;
        /// <summary>
        /// 播放句柄
        /// </summary>
        public int PlayHandle;
        /// <summary>
        /// 报警句柄
        /// </summary>
        public int AlarmHandle;
        /// <summary>
        /// 数据延迟
        /// </summary>
        public bool IsDaTaDelay
        {
            get
            {
                return ((DateTime.Now - LastJGSJ).TotalMinutes > JUDGEMENT);
            }
        }

        public DeviceState()
        {
            fcount = 0;
            NoData = true;
            Port = 0;
            Ping = false;
            LoginID = -2;
            Channel = -2;
            IsOpen = false;
            PlayHandle = -2;
            AlarmHandle = -2;
            PingOccurTime = DateTime.Now;
            LastJGSJ = DateTime.Now;
            NoDataTime = DateTime.Now;
            UploadTime = DateTime.Now;
        }

        

    }
}
